home *** CD-ROM | disk | FTP | other *** search
- Path: news.duke.edu!acheron!philabs!usenet
- From: abf@philabs.research.philips.com (Andrew Feldman)
- Newsgroups: comp.lang.c++
- Subject: Re: Class variables in C++
- Date: Wed, 14 Feb 1996 21:15:23 GMT
- Organization: Philips Laboratories, Briarcliff, NY 10510
- Distribution: inet
- Message-ID: <4ft8nn$hde@philabs.research.philips.com>
- References: <1996Feb14.165316@eigb>
- NNTP-Posting-Host: idrpc5.philabs.research.philips.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- On Wed, 14 Feb 1996 16:53:16 GMT, you wrote:
-
- >Hi,
-
- >Is it possible to create a class variable (or constant) in C++ ?
-
- >For example:
-
- >class ANIMAL
- >{
- > protected:
- > <I would like a class-variable (or constant), please>
- > UINT uNumberOfLeg=0; /* pure ?!?! */
-
- > public:
- > ...
- >};
-
- >class CAT : public ANIMAL
- >{
- > protected:
- > <I would like a class-variable (or constant), please>
- > UINT uNumberOfLeg=4;
-
- > public:
- > ...
- >};
-
- >Because I have never see a cat with 5 legs...
- >(I don't want to reserve 2 or more bytes in each instance of this class to
- >save the number of leg for a cat...)
-
- >I hope this is comprehensive...
-
- >Thanks
-
- > Laurent Guinnard
- > guinnard@eig.unige.ch
-
- >be_well++;
-
- Use virtual functions.
-
- class ANIMAL
- {
- protected:
- virtual UINT uNumberOfLeg() = 0; /* pure !!!! */
-
- public:
- ...
- };
-
- class CAT : public ANIMAL
- {
- protected:
- UINT uNumberOfLeg() { return 4; }
- public:
- ...
- };
-
-
-
-